package service;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileService {

    public static boolean saveFile(String savePath,String saveContext){
        try {
            File file=new File(savePath);
            if(file.isDirectory() && file.exists()){
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMddHHmmss");
                String lastStr = savePath.substring(0,savePath.length()-1);
                String importName="";
                if("\\".equals(lastStr) || "/".equals(lastStr)){
                    importName=savePath+simpleDateFormat.format(new Date())+"数据补录.sql";
                }else {
                    importName=savePath+"/"+simpleDateFormat.format(new Date())+"数据补录.sql";
                }
                file=new File(importName);
                FileOutputStream fileOutputStream=new FileOutputStream(file);
                fileOutputStream.write(saveContext.getBytes());
                fileOutputStream.close();
                return true;
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return false;
    }
}
